/**
 * Created with IntelliJ IDEA.
 * User: teddy zhang
 * Date: 2015-07-01
 * Time: 10:26
 */


define(function (require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    
    $.widget('rk.usersettingLangCtrl', {
        options: {
            selector: null
        },

        _create: function () {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            me._render();
            me._bind();

        },

        _render: function (data) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var lang_HTML = require('page/tmpl/usersetting/tpl_user_setting_lang.tpl');
            $(elem).html(rk.templateText(lang_HTML,{lang:window.SESSION.user.language}));
            $("#selectFormat select").selectmenu();


        },

        _init: function () {
            var me = this;
            var elem = me.element;
            var opt = me.options;
        },

        _bind: function () {
            var me = this;
            var elem = me.element;
            var opt = me.options;

            elem.find('.pg-btn-blue').on('click', function (event) {
                var lang = $("#selectFormat select").val();
                $.postJson('/json/oa_profile-edit/lang-save.action', {lang: lang}).done(function (json) {
                    if (json.status == 0) {
                        rk.noticeSuccess(rk.i18n('USERSET_SAVED'));
                        location.reload();
                    } else {
                        rk.noticeError(rk.i18n('USERSET_SYS_ERROR'));
                    }
                });
            });

        }

    });


    return $;

});